using System;

namespace Dbam.DbFramework
{
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
	public class TableRelationAttribute
		: Attribute
	{
		private string _parentColumnName;
		private string _childColumnName;
		private Type _childEntityType;

		public TableRelationAttribute(string parentColumnName, string childColumnName, Type childEntityType)
		{
			if(string.IsNullOrEmpty(parentColumnName))
				throw new ArgumentException(ErrorStrings.ParentColumnNameRequired);
			if(string.IsNullOrEmpty(childColumnName))
				throw new ArgumentException(ErrorStrings.ChildColumnNameRequired);
			if(childEntityType == null)
				throw new ArgumentNullException("childEntityType");
			if(childEntityType.GetConstructor(Type.EmptyTypes) == null)
				throw new InvalidProgramException(ErrorStrings.ChildEntityTypeNotCreatable);

			_parentColumnName = parentColumnName;
			_childColumnName = childColumnName;
			_childEntityType = childEntityType;
		}

		public string ParentColumnName
		{
			get { return _parentColumnName; }
		}

		public string ChildColumnName
		{
			get { return _childColumnName; }
		}

		public Type ChildEntityType
		{
			get { return _childEntityType; }
		}
	}
}